<cfparam name="Order_ID" type="integer" />
<cfparam name="returnView" type="string" default="orders" />
<cfparam name="printable" type="boolean" default="false" />

<cfscript>
	base = new assets.calgrants.com.Base();
	orderGateway = new assets.calgrants.com.gateway.OrderGateway();
	order = orderGateway.get(Order_ID = Order_ID);
</cfscript>

<cfif order.getOrder_ID() gt 0>

	<cfscript>
		organizationGateway = new assets.calgrants.com.gateway.OrganizationGateway();
		organization = organizationGateway.get(Organization_ID = order.getOrganization_ID());
		userGateway = new assets.calgrants.com.gateway.UserGateway();
		orderedBy = userGateway.get(User_ID = order.getOrdered_By_ID());
		orderValueGateway = new assets.calgrants.com.gateway.OrderValueGateway();
		orderValues = orderValueGateway.query();
	</cfscript>

	<script type="text/javascript" language="javascript">
	<!--
		$(function() {
			$("#orderModal").modal();
			resizeModal("orderModal");
		})
	//-->
	</script>
	
	<cfoutput>

		<div id="orderModal" class="modal modal-fullscreen" data-backdrop="static">
			<div class="modal-header">
				<h3>Order</h3>
			</div>
			<div class="modal-body">
				<div class="container-fluid">
					<div class="row-fluid">
						<div class="span12"><h4>Shipping/Order Details</h4></div>
					</div>
					<div class="row-fluid">
						<div class="span4">
							<div class="text-control clearfix">
								<label>Order ID</label>
								#order.getOrder_ID()#
							</div>
							<div class="text-control clearfix">
								<label>Order Date</label>
								#DateFormat(order.getDate_Created(), "m/d/yyyy")#
							</div>
							<div class="text-control clearfix">
								<label>Status</label>
								<cfif IsDate(order.getFulfillment_Date())>
									Shipped on #DateFormat(order.getFulfillment_Date(), "m/d/yyyy")#
								<cfelseif order.getApproved() eq 1>
									Approved
								<cfelse>
									Pending Approval
								</cfif>
							</div>
						</div>
						<div class="span4">
						
							<div class="text-control clearfix">
								<label>Shipping Address</label>
								#order.getShipping_Organization()#<br />
								#order.getShipping_Department()#<br />
								#order.getShipping_Name()#<br />
								#order.getShipping_Address()#<br />
								#order.getShipping_City()#, CA #order.getShipping_Zip_Code()#
							</div>
							<div class="text-control clearfix">
								<label>Shipping Instructions</label>
								<cfif Len(Trim(order.getShipping_Instructions())) gt 0>
									#order.getShipping_Instructions()#
								<cfelse>
									None
								</cfif>
							</div>
						</div>
						<div class="span4">
							<div class="text-control clearfix">
								<label>Ordered By</label>
								#orderedBy.getFirst_Name()# #orderedBy.getLast_Name()#<br />
								<a href="mailto:#orderedBy.getEmail()#">#orderedBy.getEmail()#</a><br />
								#orderedBy.getPhone()#<cfif Len(Trim(orderedBy.getExtension())) gt 0> x #orderedBy.getExtension()#</cfif><br />
								<br />
								#organization.getOrganization()#<br />
								#organization.getAddress()#<br />
								#organization.getCity()#, CA #organization.getZip_Code()#
							</div>
						</div>
					</div>
					<div class="row-fluid">
						<div class="span12">
							<h4>Order Items</h4>						
							<table class="table table-striped table-bordered">
								<thead>
									<tr>
										<th>Item</th>
										<th>Quantity</th>
									</tr>
								</thead>
								<tbody>
									<cfloop query="orderValues">
										<cfset itemQty = 0>
										<cfset itemIndex = ListFind(order.getOrder_Value_IDs(), Order_Value_ID)>
										<cfif itemIndex gt 0>
											<cfset itemQty = ListGetAt(order.getQuantities(), itemIndex)>
											<cfif itemQty gt 0>
												<tr>
													<td>#Description#</td>
													<td>#itemQty#</td>
												</tr>
											</cfif>
										</cfif>
									</cfloop>
								</tbody>
							</table>
						</div>
					</div>
				</div>
			</div>
			<div class="modal-footer">
				<a class="btn btn-success" href="?view=#returnView#">Close</a>
			</div>
		</div>
	
	</cfoutput>
		
<cfelse>

	<div class="alert alert-info notFound">Order not found or insufficient permissions to perform this operation</div>

</cfif>